package com.bg8loo.amateur.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {


    @GetMapping("/login")
    public String login(){
//        System.out.println("访问登录页");
        return "Anchor/login";

    }
    /**
     * 登录逻辑处理
     */
    @PostMapping("/login")
    @ResponseBody
    public String login(String username, String password){
        System.out.println(username+password);

//        /**
//         * 使用Shiro编写认证操作
//         */
//        //1.获取Subject
//        Subject subject = SecurityUtils.getSubject();
//        //2.封装用户数据
//        UsernamePasswordToken token = new UsernamePasswordToken(username,password);
//
//        //3.执行登录方法
//        try {
//            subject.login(token);
//
//            //登录成功
//            //跳转到test.html
//            return "redirect:/noteBook";
//        } catch (UnknownAccountException e) {
//            //e.printStackTrace();
//            //登录失败:用户名不存在
//            System.out.println("用户名不存在");
//            return "login";
//        }catch (IncorrectCredentialsException e) {
//            //e.printStackTrace();
//            //登录失败:密码错误
//            System.out.println("密码错误");
            return "成功";
//        }
    }

}
